Loading libraries

library(sf)
library(tmap)
library(tidyverse)
library(ggplot2)

Reading data from the internet using sf function st_read

chicago <- st_read("https://data.cityofchicago.org/resource/igwz-8jzy.geojson")
## Reading layer `igwz-8jzy' from data source `https://data.cityofchicago.org/resource/igwz-8jzy.geojson' using driver `GeoJSON'
## Simple feature collection with 77 features and 9 fields
## geometry type:  MULTIPOLYGON
## dimension:      XY
## bbox:           xmin: -87.94011 ymin: 41.64454 xmax: -87.52414 ymax: 42.02304
## epsg (SRID):    4326
## proj4string:    +proj=longlat +datum=WGS84 +no_defs

Plotting geometry column of the chicago data set with plot

plot(chicago$geometry)

Setting tmap mode to "view" with tmap_mode and plotting the community areas with tm_shape and tm_borders

tmap_mode("view")
## tmap mode set to interactive viewing
tm_shape(chicago) +
  tm_borders()

Using tidyverse function filter to get the Hyde Park community area

hyde_park <- chicago %>% filter(community == "HYDE PARK")

Plotting the community areas with Hyde Park as blue with tmap functions

tm_shape(chicago) +
  tm_borders() +
  tm_shape(hyde_park) +
  tm_fill(col = "blue")

Computing centroids of Chicago community areas with st_centroid

centroids <- st_centroid(chicago)

Ploting centroids in red, Chicago community areas, and Hyde Park in Blue with tmap functions

tm_shape(chicago) +
  tm_borders() +
  tm_shape(hyde_park) +
  tm_fill(col = "blue") +
  tm_shape(centroids) +
  tm_dots(col = "red")